package ferp.android.ads.interstitial;

import android.app.Activity;
import android.content.Context;
import ferp.android.managers.BonusManager;

/**
 * User: olegs
 * Date: 14/07/2014 10:49
 */
public class InterstitialAdManager
{
  public interface Provider
  {
    // load an interstitial ad
    void load(Context context);
    // show an interstitial ad
    void show();
  }

  public static void setEnabled(boolean enabled) {InterstitialAdManager.enabled = enabled;}

  public static void load(Activity activity)
  {
    if (enabled && !BonusManager.isActive(activity))
      try
      {
        // the next line may throw permission exception on getTasks() method (google bug?)
        adMob.load(activity.getApplicationContext());
      }
      catch (Exception e)
      {
        // log?
      }
  }

  public static void show(Activity activity)
  {
    if (enabled && !BonusManager.isActive(activity))
      adMob.show();
  }

  public static void stop()
  {
    // for symmetry purpose (like in MediationAdManager)
  }

  // AdMob provider
  private static final AdmobInterstitialAdProvider adMob = new AdmobInterstitialAdProvider();
  // enabled flag
  private static boolean enabled;
}
